from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dim.tab.dim_tab_agent_point_base import jms_dim__dim_tab_agent_point_base
from jms.dim.tab.dim_tab_terminal_secret_base import jms_dim__dim_tab_terminal_secret_base
from jms.dwd.tab.dwd_tab_barscan_collect_base_dt import jms_dwd__dwd_tab_barscan_collect_base_dt
from jms.time_sensor.time_after_05_30 import time_after_05_30

jms_dm__dm_service_quality_bacth_out_store_detail_dt  = SparkSqlOperator(
    task_id='jms_dm__dm_service_quality_bacth_out_store_detail_dt',
    task_concurrency=1,
    pool_slots=4,
    master='yarn',
    execution_timeout = timedelta(minutes=45),
    email=['wangmenglei@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='dm_service_quality_bacth_out_store_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_service_quality_bacth_out_store_detail_dt/execute.hql',
    driver_memory='4G',
    driver_cores=4,
    executor_cores=4,
    executor_memory='8G',
    num_executors=8,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 8,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '2G',  # 堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict', # 动态分区
        'spark.hadoop.hive.exec.dynamic.partition': 'true',
        'spark.sql.shuffle.partitions': 90,
        'spark.yarn.maxAppAttempts':1,
        'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=4',
    },
    hiveconf={
       'hive.exec.dynamic.partition' : 'true',  # 动态分区
       'hive.exec.dynamic.partition.mode' : 'nonstrict',
       'hive.exec.max.dynamic.partitions' : 400,  # 每天生成 20 个分区
       'hive.exec.max.dynamic.partitions.pernode': 400,  # 每天生成 20 个分区
    },
    yarn_queue='pro',
)


jms_dm__dm_service_quality_bacth_out_store_detail_dt << [
    jms_dim__dim_tab_agent_point_base,
    jms_dim__dim_tab_terminal_secret_base,
    jms_dwd__dwd_tab_barscan_collect_base_dt,
    time_after_05_30
]